package com.rc.web.mapper;

import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.rc.pojo.dto.knowledge.KnowledgePageQuery;
import com.rc.pojo.po.Knowledge;
import com.rc.pojo.vo.knowldege.KnowledgePageVO;

import java.util.List;

import static com.rc.pojo.po.table.IllTableDef.ILL;
import static com.rc.pojo.po.table.KnowledgeTableDef.KNOWLEDGE;

/**
 * 知识库表 映射层。
 * 提供知识库相关的数据库操作接口
 */
public interface KnowledgeMapper extends BaseMapper<Knowledge> {

    /**
     * 根据病害ID列表查询知识库
     * @param illIds 病害ID列表
     * @return 知识库列表
     */
    default List<Knowledge> selectListByIllIds(List<Long> illIds){
        return selectListByQuery(QueryWrapper.create()
                .where(KNOWLEDGE.ILL_ID.in(illIds))
        );
    }

    /**
     * 分页查询知识库
     * @param dto 分页查询条件
     * @return 分页结果
     */
    default Page<KnowledgePageVO> selectPage(KnowledgePageQuery dto){
        return paginateAs(dto.getCurrent(),dto.getPageSize(), QueryWrapper.create()
                        .select(KNOWLEDGE.ALL_COLUMNS,ILL.NAME.as("illName"))
                        .join(ILL).on(ILL.ID.eq(KNOWLEDGE.ILL_ID))
                        .where(KNOWLEDGE.TITLE.like(dto.getTitle()))
                ,KnowledgePageVO.class
        );
    }
}
